home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / tsbat146.zip / PROMPT.TXT < prev    next >
Text File  |  1994-09-04  |  6KB  |  135 lines

  1. PROMPT.TXT prompt and related tips                    Sun 4-Sep-94
  2. ==================================
  3.                                                All rights reserved
  4.                             Copyright (c) 1993, 1994 by Timo Salmi
  5.  
  6. ..................................................................
  7. Prof. Timo Salmi      Co-moderator of comp.archives.msdos.announce
  8. Moderating at garbo.uwasa.fi anonymous FTP  archives  128.214.87.1
  9. Faculty of Accounting & Industrial Management; University of Vaasa
  10. Internet: ts@uwasa.fi   BBS +(358)-61-3170972; FIN-65101,  Finland
  11. ..................................................................
  12.  
  13.   ┌───────────────────────────────────────────────────────────┐
  14.   │ This file belongs to TSBAT*.ZIP. Please do not distribute │
  15.   │ this prompt.txt file separately!                          │
  16.   └───────────────────────────────────────────────────────────┘
  17.  
  18. 1) If you have programs that can shell to dos it would be nice to
  19. know whether you currently are in a dos shell or not. Else you might
  20. call the same program again from the shell and eventually run out of
  21. memory. There is a rather straight-forward trick for this. Assume
  22. that your program is called prog.exe. You can always call the
  23. program from a batch, say pro.bat. Include the following lines in
  24. your batch:
  25.  
  26.   set _prompt=%prompt%
  27.   set prompt=%_prompt%[in shell or whatever text]
  28.   prog %1 %2 %3 %4 %5 %6 %7 %8 %9
  29.   set prompt=%_prompt%
  30.   set prompt=
  31.  
  32. The method will not work or will produce unexpected results if the
  33. program itself manipulates the prompt when shelling to Dos. Some
  34. (usually advanced) programs do.
  35.  
  36. Another trick to avoid double loading is shown in the following
  37. skeleton
  38.   if "%_loaded%"=="yes" exit
  39.   set _loaded=yes
  40.   prog %1 %2 %3 %4 %5 %6 %7 %8 %9
  41.   set _loaded=
  42.  
  43.  
  44. 2) A frequently asked question about ansi.sys is now does one use it
  45. to redefine keyboard keys. Here is an example which redefines the F1
  46. key invoke the directory "dir" command, the F2 key to invoke the
  47. "dir/w" command, and the F3 to type the Scandinavian letter ä.
  48.    prompt $e[0;59;"dir";13p
  49.    prompt $e[0;60;"dir/w";13p
  50.    prompt $e[0;61;"ä"p
  51.    prompt $p$g
  52.  
  53. The last line is needed to restore the prompt in its usual format
  54. (which I have as $p$g).
  55.  
  56. To cancel the definitions apply
  57.    prompt $e[0;59;;p
  58.    prompt $e[0;60;;p
  59.    prompt $e[0;61;;p
  60.    prompt $p$g
  61.  
  62. This system requires that you have ansi.sys loaded in your
  63. config.sys file
  64.    device=c:\dos\ansi.sys
  65.  
  66. A related FAQ (Frequently Asked Question) is how to exchange the .
  67. and , keys.  here is how to do that
  68.   @echo <ESC>[",";"."p<ESC>[".";","p
  69. To reverse the effect, apply
  70.   @echo <ESC>[",";","p<ESC>[".";"."p
  71. This trick will not work for exchanging the CTRL and SHIFT keys.
  72. They are not mappable this way.
  73.  
  74. Note that ansi.sys replacements like zansi.sys (which I normally use
  75. myself) do not have the key-redefinition feature. This has one
  76. advantages, that is protecting you against the so-called ansi bombs.
  77.  
  78. The 0;59 pair defines F1 because it is that key's scan code. To get
  79. the scan codes of the different keys you need either a scan code
  80. table or a program that gives the scan code of the key you have
  81. pressed. One such program is SCANCODE.EXE in garbo.uwasa.fi:/pc/ts/
  82. tsbase11.zip (or whatever version number is the current).
  83.  
  84.  
  85. 3) You can devise quite complicated ansi prompts to do flashy
  86. things although much of this is rather computer entertainment than
  87. serious usage. Let look at some examples
  88.  
  89. My ordinary prompt is the simple
  90.    prompt $p$g
  91. which displays the directory followed bu the > sign. Furthermore I
  92. use bright yellow on black, but for that I apply echo <ESC>[40;33;1m
  93.  
  94. Let's build from that.
  95.    prompt $d $t$_$p$g
  96. Gives the date and the time on the first line ($d $t), then on the
  97. second ($_) gives the current directory ($p) and the > sign ($g).
  98.  
  99. Lets take a little more complicated example next:
  100.    prompt $e[s$e[1;69H$t$h$h$h$e[u$p$g
  101. This is of of the basic prompt tricks, and it puts the time in the
  102. upper right corner of the screen. First the current cursor postion
  103. is stored ($e[s); the cursor is moved to row 1, column 69 ($e[1;69H)
  104. the time is displayed ($t); the hundredths of a second are deleted
  105. ($h$h$h); the original cursor position is restored ($e[u); and
  106. finally the current directory and the > sign are displayed ($p$g).
  107.  
  108. The next obvious step is to display the time in some garish reverse.
  109. For the normal part of the prompt lets use my own default which is
  110. bright yellow on black ($e[40;33;1m).
  111.    prompt $e[s$e[1;69H$e[41;32;1m$t$e[40;33;1m$h$h$h$e[u$p$g
  112. The time is displayed in bright green on red ($e[41;32;1m).
  113.  
  114. The interpretation of the following prompt is left as an exercise:
  115.    prompt $e[s$e[H$e[43;30m$e[KDirectory $p $d $t $h$h$h$h $v
  116.           $e[40;33;1m$e[2;1H$e[K$e[u$p$g
  117. Note that you must have everything on one line only. The wrap here
  118. is just for readability.
  119.  
  120. One example of an "entertainment" prompt just to give the general
  121. idea:
  122.    prompt $e[s$_$e[40;37m██$e[34m██$e[37m████$_$e[34m████████
  123.           $e[40;37m$_██$e[34m██$e[37m████$e[40;33m $p$g
  124. Note that you must have everything on one line only. The wrap here
  125. is just for readability.
  126.  
  127. The difference in using the echo and the prompt for setting the
  128. screen colors is that the echo is invoked only when you apply it,
  129. but the prompt is called each time the dos prompt appears.
  130.  
  131.  
  132. 4) If you are having problems you can "debug" your prompt by giving
  133. the set command in MsDos which displays your environment variables
  134. including the prompt variable.
  135.